<template>
  <div class="dashboard">
    <!-- 页面标题 -->
    <div class="page-header">
      <h2>仪表盘</h2>
      <p>欢迎回来，这是您的系统概览</p>
    </div>
    
    <!-- 统计卡片 -->
    <div class="stats-cards">
      <div class="stat-card">
        <div class="stat-info">
          <h3>总用户数</h3>
          <p class="stat-value">5,246</p>
          <p class="stat-change">+24% <span class="text-green-500">较上月</span></p>
        </div>
        <div class="stat-icon">
          <Users size="24" />
        </div>
      </div>
      
      <div class="stat-card">
        <div class="stat-info">
          <h3>今日访问量</h3>
          <p class="stat-value">1,842</p>
          <p class="stat-change">+12% <span class="text-green-500">较昨日</span></p>
        </div>
        <div class="stat-icon">
          <Eye size="24" />
        </div>
      </div>
      
      <div class="stat-card">
        <div class="stat-info">
          <h3>销售额</h3>
          <p class="stat-value">¥32,589</p>
          <p class="stat-change">-8% <span class="text-red-500">较上月</span></p>
        </div>
        <div class="stat-icon">
          <DollarSign size="24" />
        </div>
      </div>
      
      <div class="stat-card">
        <div class="stat-info">
          <h3>订单数</h3>
          <p class="stat-value">456</p>
          <p class="stat-change">+18% <span class="text-green-500">较昨日</span></p>
        </div>
        <div class="stat-icon">
          <Package size="24" />
        </div>
      </div>
    </div>
    
    <!-- 国际化测试组件 -->
    <I18nTest />
    
    <!-- 图表区域 -->
    <div class="charts-section">
      <!-- 折线图 - 销售趋势 -->
      <div class="chart-card">
        <div class="chart-header">
          <h3>销售趋势</h3>
          <Dropdown v-model="dateRange" :options="dateRangeOptions" placeholder="选择时间范围" />
        </div>
        <div class="chart-content">
          <Chart type="line" :data="lineChartData" :options="lineChartOptions" />
        </div>
      </div>
      
      <!-- 柱状图 - 月度对比 -->
      <div class="chart-card">
        <div class="chart-header">
          <h3>月度对比</h3>
        </div>
        <div class="chart-content">
          <Chart type="bar" :data="barChartData" :options="barChartOptions" />
        </div>
      </div>
      
      <!-- 饼状图 - 用户分布 -->
      <div class="chart-card">
        <div class="chart-header">
          <h3>用户分布</h3>
        </div>
        <div class="chart-content">
          <Chart type="pie" :data="pieChartData" :options="pieChartOptions" />
        </div>
      </div>
      
      <!-- 环形图 - 漏斗转化 -->
      <div class="chart-card">
        <div class="chart-header">
          <h3>转化漏斗</h3>
        </div>
        <div class="chart-content">
          <Chart type="doughnut" :data="funnelChartData" :options="funnelChartOptions" />
        </div>
      </div>
    </div>
    
    <!-- 最近订单表格 -->
    <div class="recent-orders">
      <div class="orders-header">
        <h3>最近订单</h3>
        <Button>查看全部</Button>
      </div>
      
      <DataTable :value="orders" responsiveLayout="scroll">
        <Column field="id" header="订单编号" />
        <Column field="customer" header="客户" />
        <Column field="amount" header="金额" />
        <Column field="status" header="状态" />
        <Column field="date" header="日期" />
        <Column header="操作">
          <template #body>
            <Button size="small" icon="Eye" />
            <Button size="small" icon="Edit" class="ml-2" />
          </template>
        </Column>
      </DataTable>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive } from 'vue'
// import { Users, Eye, DollarSign, Package } from 'primevue/icons' // 暂时注释，PrimeVue 4.x版本图标可能需要单独安装
import DataTable from 'primevue/datatable'
import Column from 'primevue/column'
import Button from 'primevue/button'
import Dropdown from 'primevue/dropdown'
import Chart from 'primevue/chart'
import I18nTest from '@/components/I18nTest.vue'

// 日期范围选项
const dateRangeOptions = [
  { label: '今日', value: 'today' },
  { label: '本周', value: 'week' },
  { label: '本月', value: 'month' },
  { label: '本季度', value: 'quarter' },
  { label: '本年', value: 'year' }
]

// 选中的日期范围
const dateRange = ref('month')

// 订单数据（示例）
const orders = ref([
  { id: 'ORD-2023-001', customer: '张三', amount: '¥1,299.00', status: '已完成', date: '2023-12-01' },
  { id: 'ORD-2023-002', customer: '李四', amount: '¥899.00', status: '处理中', date: '2023-12-01' },
  { id: 'ORD-2023-003', customer: '王五', amount: '¥2,499.00', status: '已完成', date: '2023-12-02' },
  { id: 'ORD-2023-004', customer: '赵六', amount: '¥1,699.00', status: '已取消', date: '2023-12-02' },
  { id: 'ORD-2023-005', customer: '钱七', amount: '¥3,299.00', status: '处理中', date: '2023-12-03' }
])

// 折线图数据 - 销售趋势
const lineChartData = reactive({
  labels: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
  datasets: [
    {
      label: '销售额 (万元)',
      data: [65, 59, 80, 81, 56, 55, 40, 45, 60, 70, 85, 90],
      fill: false,
      borderColor: '#42A5F5',
      backgroundColor: 'rgba(66, 165, 245, 0.1)',
      tension: 0.4
    },
    {
      label: '利润 (万元)',
      data: [28, 48, 40, 19, 86, 27, 90, 35, 50, 40, 60, 70],
      fill: false,
      borderColor: '#66BB6A',
      backgroundColor: 'rgba(102, 187, 106, 0.1)',
      tension: 0.4
    }
  ]
})

const lineChartOptions = reactive({
  plugins: {
    legend: {
      labels: {
        color: '#495057'
      }
    }
  },
  scales: {
    x: {
      ticks: {
        color: '#495057'
      },
      grid: {
        color: '#ebedef'
      }
    },
    y: {
      ticks: {
        color: '#495057'
      },
      grid: {
        color: '#ebedef'
      }
    }
  }
})

// 柱状图数据 - 月度对比
const barChartData = reactive({
  labels: ['1月', '2月', '3月', '4月', '5月', '6月'],
  datasets: [
    {
      label: '2023年',
      backgroundColor: '#42A5F5',
      data: [65, 59, 80, 81, 56, 55]
    },
    {
      label: '2024年',
      backgroundColor: '#66BB6A',
      data: [28, 48, 40, 19, 86, 27]
    }
  ]
})

const barChartOptions = reactive({
  plugins: {
    legend: {
      labels: {
        color: '#495057'
      }
    }
  },
  scales: {
    x: {
      ticks: {
        color: '#495057'
      },
      grid: {
        color: '#ebedef'
      }
    },
    y: {
      ticks: {
        color: '#495057'
      },
      grid: {
        color: '#ebedef'
      }
    }
  }
})

// 饼状图数据 - 用户分布
const pieChartData = reactive({
  labels: ['移动端', '桌面端', '平板端', '其他'],
  datasets: [
    {
      data: [45, 35, 15, 5],
      backgroundColor: [
        '#42A5F5',
        '#66BB6A',
        '#FFA726',
        '#EF5350'
      ],
      hoverBackgroundColor: [
        '#64B5F6',
        '#81C784',
        '#FFB74D',
        '#E57373'
      ]
    }
  ]
})

const pieChartOptions = reactive({
  plugins: {
    legend: {
      labels: {
        color: '#495057'
      }
    }
  }
})

// 环形图数据 - 转化漏斗
const funnelChartData = reactive({
  labels: ['访问', '注册', '试用', '付费', '续费'],
  datasets: [
    {
      data: [100, 60, 40, 25, 15],
      backgroundColor: [
        '#42A5F5',
        '#66BB6A',
        '#FFA726',
        '#EF5350',
        '#AB47BC'
      ],
      hoverBackgroundColor: [
        '#64B5F6',
        '#81C784',
        '#FFB74D',
        '#E57373',
        '#BA68C8'
      ]
    }
  ]
})

const funnelChartOptions = reactive({
  plugins: {
    legend: {
      labels: {
        color: '#495057'
      }
    }
  }
})
</script>

<style scoped>
.dashboard {
  padding: 0;
}

.page-header {
  padding: 20px 0;
}

.page-header h2 {
  margin: 0;
  font-size: 24px;
  color: #333;
}

.page-header p {
  margin: 8px 0 0 0;
  color: #666;
  font-size: 14px;
}

.stats-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
  margin-bottom: 20px;
}

.stat-card {
  background-color: #fff;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.stat-info h3 {
  margin: 0 0 8px 0;
  font-size: 14px;
  color: #666;
  font-weight: normal;
}

.stat-value {
  margin: 0 0 4px 0;
  font-size: 24px;
  font-weight: bold;
  color: #333;
}

.stat-change {
  margin: 0;
  font-size: 12px;
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background-color: #f0f0ff;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #646cff;
}

.charts-section {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 20px;
  margin-bottom: 20px;
}

.chart-card {
  background-color: #fff;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.chart-header h3 {
  margin: 0;
  font-size: 18px;
  color: #333;
}

.chart-content {
  height: 350px;
  position: relative;
}

.recent-orders {
  background-color: #fff;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.orders-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.orders-header h3 {
  margin: 0;
  font-size: 18px;
  color: #333;
}

/* 响应式布局 */
@media (max-width: 768px) {
  .charts-section {
    grid-template-columns: 1fr;
  }
}
</style>